package com.ewhale.feitengguest.presenter.user.auth;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.view.auth.ForgetPasswordView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class ForgetPasswordPresenter extends IPresenter {

    private String userForget = "app/common/forgetPwdByPhone.json";
    private String shopForget = "app/common/shopForgetPassword.json";


    public void getCode(String sessionId,String registerPhone) {
        mView.showProLoading();
        request(1, ApiHelper.AUTH_API.getCode(sessionId,registerPhone, "2"), null);
    }

    public void resetPwd(int loginType,String registerPhone, String code, String registerPwd) {
        mView.showProLoading();
        if(loginType == 0){
            request(2, ApiHelper.AUTH_API.forgetPassword(userForget,registerPhone, code,registerPwd,registerPwd), null);
        }else{
            request(2, ApiHelper.AUTH_API.forgetShopPassword(shopForget,registerPhone, code,registerPwd,registerPwd), null);
        }
    }
    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((ForgetPasswordView) mView).getCodeSuccess();
                break;
            case 2:
                ((ForgetPasswordView) mView).resetSuccess();
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
